package io.ukoko.bhwms.controller;

import io.swagger.annotations.Api;
import io.ukoko.bhwms.dto.Page;
import io.ukoko.bhwms.dto.RecordInOutDto;
import io.ukoko.bhwms.dto.Result;
import io.ukoko.bhwms.entity.RecordStock;
import io.ukoko.bhwms.service.RecordStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "库存模块")
@CrossOrigin
@RestController
public class RecordStockController {

    @Autowired
    private RecordStockService recordStockService;

    /**
     * 入库操作
     */
    @PostMapping(value = "/inRecordStock")
    public Object inRecordStock(@RequestBody RecordInOutDto recordInOutDto){
        recordStockService.inRecordStock(recordInOutDto);
        RecordStock rs = recordStockService.getRecordStockByRepoIdAndProductId(recordInOutDto.getRepoId(), recordInOutDto.getProductId());
        return new Result(rs);
    }
    /**
     * 出库操作
     */
    @PostMapping(value = "/outRecordStock")
    public Object outRecordStock(@RequestBody RecordInOutDto recordInOutDto){
        recordStockService.outRecordStock(recordInOutDto);
        RecordStock rs = recordStockService.getRecordStockByRepoIdAndProductId(recordInOutDto.getRepoId(), recordInOutDto.getProductId());
        return new Result(rs);
    }

    /**
     * 分页获取库存列表
     */
    @GetMapping(value = "/getRecordStockPage")
    public Object getRecordStockPage(Integer pageNo,Integer pageSize,Integer repoId,Integer productId){
        Page page = recordStockService.getRecordStockPage(pageNo, pageSize, repoId, productId);
        return new Result(page);
    }
}
